/*eslinet-disable*/
import React from 'react'
import request from '../../utils/request'
import { Form, Field,Button,NavBar} from 'react-vant';
import './login.css'
const Loginpage = (props) => {

    const {history}=props

    const gohome=()=>{
        history.push('/home')
        alert('登录成功')
    }
    const [form] = Form.useForm();

    const onFinish = (values) => {
        console.log('form submit', values);
        request({
            url:"http://47.102.145.189:8009/admin/login",
            method:"post",
            data:{
                username:values.username,                                
                password:values.password
            }
        }).then(res=>{
            console.log(res);
            if(res.code===200){
                alert('登录成功')
                history.push('/home')
            }else{
                alert('登陆失败！！')
            }
        })
    };
    return (
        <div>
        <NavBar onBack={() => props.history.go(-1)}>账号登录</NavBar>
        <Form form={form} onFinish={onFinish} showValidateMessage={false}>
            <Form.Item name='username' validateTrigger='onBlur' rules={[{ required: true, message: '请输入账号' }]}>
                <Field placeholder='请输入账号' />
            </Form.Item>
            <Form.Item name='password' validateTrigger='onBlur' rules={[{ required: true, message: '请输入密码', }]}>
                <Field placeholder='请输入密码' type="password" />
            </Form.Item>
            <div style={{ padding: '10px' }} >
                <Button
                    type="info"
                    nativeType='submit'
                    block
                onClick={()=>{
                    gohome()
                }}>
                    登录
            </Button>
            </div>
        </Form>
    </div>
    )
}
export default Loginpage
